# 复杂查询控制器
from flask import request, jsonify
from app.api.services.complex_query_examples import ComplexQueryExamples
from app.utils.response import response_success, response_fail

class ComplexQueryController:
    """复杂查询控制器"""
    
    @staticmethod
    def test_basic_filtering():
        """测试基本过滤查询"""
        try:
            result = ComplexQueryExamples.basic_filtering()
            return response_success(data=result)
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_logical_operators():
        """测试逻辑运算符查询"""
        try:
            result = ComplexQueryExamples.logical_operators()
            return response_success(data={"users_count": result})
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_pattern_matching():
        """测试模式匹配查询"""
        try:
            result = ComplexQueryExamples.pattern_matching()
            return response_success(data={"users_count": result})
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_ordering_and_limiting():
        """测试排序和限制查询"""
        try:
            result = ComplexQueryExamples.ordering_and_limiting()
            return response_success(data=result)
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_aggregation_functions():
        """测试聚合函数查询"""
        try:
            result = ComplexQueryExamples.aggregation_functions()
            return response_success(data=result)
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_date_and_time_queries():
        """测试日期和时间查询"""
        try:
            result = ComplexQueryExamples.date_and_time_queries()
            return response_success(data=result)
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_raw_sql_queries():
        """测试原生SQL查询"""
        try:
            result = ComplexQueryExamples.raw_sql_queries()
            return response_success(data={"users_count": result})
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_subqueries():
        """测试子查询"""
        try:
            result = ComplexQueryExamples.subqueries()
            return response_success(data=result)
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_case_statements():
        """测试CASE语句"""
        try:
            result = ComplexQueryExamples.case_statements()
            return response_success(data={"users_count": result})
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_union_queries():
        """测试UNION查询"""
        try:
            result = ComplexQueryExamples.union_queries()
            return response_success(data={"users_count": result})
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_window_functions():
        """测试窗口函数"""
        try:
            result = ComplexQueryExamples.window_functions()
            return response_success(data={"users_count": result})
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")
    
    @staticmethod
    def test_performance_tips():
        """测试查询性能优化技巧"""
        try:
            result = ComplexQueryExamples.performance_tips()
            return response_success(data={"message": result})
        except Exception as e:
            return response_fail(msg=f"查询失败: {str(e)}")